<?
Error_Reporting(E_ALL & ~E_NOTICE);


#-----------including phpbb

 define('IN_PHPBB', true); 
 $phpbb_root_path = 'forum/'; 
 include($phpbb_root_path . 'extension.inc'); 
 include($phpbb_root_path . 'common.'.$phpEx); 
 
 // 
// Start session management 
// 
 $userdata = session_pagestart($user_ip, PAGE_INDEX); 
 init_userprefs($userdata); 

#-----------configure host 

 define ("database","motolifemk_adv");
 define ("host","localhost");
 define ("user","motolifemk_uadv");
 define ("passwd","kd1501832");
 
#-----------database

 $tbl_questions = "forumvoteq";
 $tbl_answers = "forumvotea";
 $tbl_statquestions = "forumvote_stat";
 $tbl_ips = "forumvote_users"; 
 
#-----------classes 

 include_once "classes/database.class";
 $c_db = new Database(host,user,passwd,database);   

 include_once "classes/questions_class.php"; 
 $c_questions = new Questions($c_db,$tbl_questions,$tbl_answers,$tbl_statquestions,$tbl_ips);
   
#-----------confiqure other

  include_once ("include/configSmarty.php");   

//
echo "ddd';
   $allquestions_ar = $c_questions -> SelectActiveQuestion();

   $message = "";
   
   if (!isset($qm))
      $qm = "all";	  
   
   if ( isset($_GET['qid']) )
      $qid = (int)$_GET['qid'];
   else 
      $qid = $allquestions_ar[0]['id'];

   if ( isset($_GET['act']) )
      $act = $_GET['act'];
   elseif ( isset($_POST['act']) )
      $act = $_POST['act'];
   else $act = "";	  
   if ( isset($_POST['aid']) )
      $aid = $_POST['aid'];          
   if ($userdata && $userdata['user_id'] != -1)
   {
   if ($c_questions -> CheckID($qid,$userdata['user_id'])) 
      $act = 'results';
     
   $answers_ar = $c_questions -> SelectAnswerByQuestion($qid);
   $question = $c_questions -> SelectOneQuestion($qid);
   if ( $act == "answer" )
   {
    //    $IP = $_SERVER['REMOTE_ADDR'];
        if ($c_questions -> CheckID($qid,$userdata['user_id'])) 
        {
           $c_questions -> UpdateForumvoteStatistic($aid);
           $c_questions -> InsertID($qid,$userdata['user_id']);
           $act = "results";
        }
        else $act = "results";
   }
  } 
  else $act = 'results';
  
   if ( $act == "results" )
   {
       $acountarr = count($answers_ar); 
	   $statistics_ar = array();
	   for ($j=0;$j<$acountarr;$j++)
       { 
           $statistics = $c_questions ->SelectOneStatistic($answers_ar[$j]['id']);
  	       $statistics_ar[$j]['aid'] = $statistics[0]['aid'];
	       $statistics_ar[$j]['count'] = $statistics[0]['count'];
  	       $statistics_ar[$j]['score'] = $statistics[0]['score'];
       }
	//   $stat_res = $c_questions -> MakeForumvoteStatistic($statistics_ar);
       $smarty->assign('stat_res', $stat_res);
   }
   

  $smarty->assign('allquestions_ar', $allquestions_ar);
  $smarty->assign('qid', $qid);
  $smarty->assign('act',$act);
  $smarty->assign('answers_ar', $answers_ar);
  $smarty->assign('question', $question);
  $smarty->assign('message', $message);
  $smarty->assign('user_id', $userdata['user_id']);

  if ($act == "results")
     $smarty->display('site/forumvote.tpl'); 
  else
     $smarty->display('site/plforumvote.tpl'); 
 
?>
